﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WorldEvolution
{
    public class Region : Object
    {
        static Dictionary<ulong, Region> mRegionDict = new Dictionary<ulong, Region>();
        public static Dictionary<ulong, Region> Regions { get { return mRegionDict; } }

        public static Region Create()
        {
            var r = new Region();
            mRegionDict[r.ID] = r;
            r.OnCreate();
            return r;
        }

        public virtual void OnCreate() { }

        public void Evolute()
        {
            if(mZones.Count == 0)
            {
                var z = Zone.Create();
                mZones[z.ID] = z;
                z.Evolute();
            }
            else
            {//每次随机进化一个
                var zones = mZones.Values.ToArray();
                var ran = Util.Rand.Next(zones.Length);
                zones[ran].Evolute();
            }
        }

        public void LoadByDB(DBData.RegionData dbData)
        {
            mData = dbData;
        }

        protected Dictionary<ulong, Zone> mZones = new Dictionary<ulong, Zone>();

        private DBData.RegionData mData;
    }
}
